using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientRadiologyController : Controller
    {
		private readonly IAdmissionRepository admissionRepository;
		private readonly IRadiologyItemRepository radiologyitemRepository;
		private readonly IPatientRadiologyRepository patientradiologyRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientRadiologyController() //: this(new AdmissionRepository(), new RadiologyItemRepository(), new PatientRadiologyRepository())
        {
            admissionRepository = Registry.RepositoryFactory.GetAdmissionRepository();
            radiologyitemRepository = Registry.RepositoryFactory.GetRadiologyItemRepository();
            patientradiologyRepository = Registry.RepositoryFactory.GetPatientRadiologyRepository();
        }

        public PatientRadiologyController(IAdmissionRepository admissionRepository, IRadiologyItemRepository radiologyitemRepository, IPatientRadiologyRepository patientradiologyRepository)
        {
			this.admissionRepository = admissionRepository;
			this.radiologyitemRepository = radiologyitemRepository;
			this.patientradiologyRepository = patientradiologyRepository;
        }

        //
        // GET: /PatientRadiology/

        public ViewResult Index()
        {
            return View(patientradiologyRepository.All);//Including(patientradiology => patientradiology.Admission, patientradiology => patientradiology.Pictures, patientradiology => patientradiology.Attachments));
        }

        //
        // GET: /PatientRadiology/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(patientradiologyRepository.Find(id));
        }

        //
        // GET: /PatientRadiology/Create

        public ActionResult Create()
        {
			ViewBag.PossibleAdmissions = admissionRepository.All;
			ViewBag.PossibleRadiologyItems = radiologyitemRepository.All;
            return View();
        } 

        //
        // POST: /PatientRadiology/Create

        [HttpPost]
        public ActionResult Create(PatientRadiology patientradiology)
        {
            if (ModelState.IsValid) {
                patientradiologyRepository.Create(patientradiology);
                patientradiologyRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleAdmissions = admissionRepository.All;
				ViewBag.PossibleRadiologyItems = radiologyitemRepository.All;
				return View();
			}
        }
        
        //
        // GET: /PatientRadiology/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleAdmissions = admissionRepository.All;
			ViewBag.PossibleRadiologyItems = radiologyitemRepository.All;
             return View(patientradiologyRepository.Find(id));
        }

        //
        // POST: /PatientRadiology/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientRadiology patientradiology)
        {
            if (ModelState.IsValid) {
                patientradiologyRepository.Update(patientradiology);
                patientradiologyRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleAdmissions = admissionRepository.All;
				ViewBag.PossibleRadiologyItems = radiologyitemRepository.All;
				return View();
			}
        }

        //
        // GET: /PatientRadiology/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(patientradiologyRepository.Find(id));
        }

        //
        // POST: /PatientRadiology/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var pr = patientradiologyRepository.Find(id);
            patientradiologyRepository.Delete(pr);
            patientradiologyRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

